<?php
/**
 * Project: ShopWorx- making your life easier
 *   
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @Author Chris 
 * @File Debug.class.php
 * @Version 1.0.0
 * @Copyright 2008 Shopworx (c) 
 * @Year 2008
 * @access Public 
 */
 
 Define('DEBUG_LOADED', true);
 
 /*** debug class
  *
  *@package debug
  */
  
  class debug{
	var $Textcolor = 'red';
	
	function debug($params = null)
	{
		//debug constructor method
		$this->color = $params['color'];
		$this->prefix = $params['prefix'];
		$this->line = 1;
		$this->buffer_str = null;
		$this->buffer = $params['buffer'];
		$this->banner_printed = false;
	}
	
	function print_banner()
	{
		if ($this->banner_printed == true)
		{
			return 0;
		}

 	$out = "Debug console for &ldquo; $this->prefix &rdquo; application";
		if ($this->buffer == true){
			$this->buffer_str .= $out;
		} else {
			echo $out;
			$this->banner_printed = true;
		}
		return 1;
	}
	
	function write($msg)
    {
		$out = sprintf('<font color=\"%s\">%03d&nbsp;&gt;&nbsp; </font>' .
                       '<font color=\"%s\">%s</font><br /> \n' ,
					   $this->Textcolor,
					   $this->line++,
					   $this->color,
					   $msg);

		if($this->buffer == true)
		{
			$this->buffer_str .= $out;
		} else {
            echo $out;
		}
    }
    
    function debug_array($hash = null)
    {
		while(list($k, $v) = each($hash))
		{
			$this->write("$k = $v");
		}
    }
    
    function set_buffer()
    {
		$this->buffer = true;
    }
    
    function reset_buffer()
    {
		$this->buffer = false;
		$this->buffer_str = null;
    }
    
    function flush_buffer()
    {
		echo "<link href=\"Includes/libs/extjs/resources/css/ext-all.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />";
		echo "<script src = \"Includes/libs/extjs/adapter/ext/ext-base.js\"></script>";
        echo "<script src =\"Includes/libs/extjs/ext-all.js\"></script>";
		echo "<script>
                 Ext.onReady(function(){
				  message = '$this->buffer_str';
                     var p = new Ext.Window({
                                 title: 'Debug console for  $this->prefix application',
                                 collapsible:true,
                                 height: 150,
                                 width: 500,
                                 draggable: true,
                                 html: message,
                                 y: 600
                                 });
                               p.show();
                               })
			 </script><div id=\"container\"></div>";
  $this->buffer = false;

    }
  }

